// const path = require('path');
const {
  override,
  fixBabelImports,
  overrideDevServer,
  addWebpackExternals,
  addLessLoader,
} = require('customize-cra');

//自定义主题
const { theme, proxy } = require('./libs/config.js');

//自定义添加plugin / 内置api addWebpackPlugin
// const webpack = require('webpack');
// const addMyPlugin = config => {
//   config.plugins.push(new webpack.ProvidePlugin({
//     'window.ccc': 'jquery'
//   }))
//   return config
// }
//
// addWebpackExternals 添加外部依赖项，将库卸载到CDN。
// let custom = config=>{
//   config.devtool = false;
//   return config
// }

const devServerConfig = (config) => {
  config.proxy = proxy;

  return config;
};

// const publicPathPlugin = (config) => {
// let buildPath = _config.buildPath;
// config.output.path = path.join(__dirname, buildPath);\

// config.plugins.push(new WriteFilePlugin());
// fs.removeSync(buildPath);
// fs.copySync('./public/', buildPath);
// console.log(config.output);
// return config;
// };

module.exports = {
  webpack: override(
    // publicPathPlugin,
    fixBabelImports('import', { libraryName: 'antd-mobile', style: true }),
    addLessLoader({
      lessOptions:{
        javascriptEnabled: true,
        modifyVars: theme,
      }
    }),
    // 抽离外部依赖
    addWebpackExternals({
      //   react: 'React',
      //   'react-dom': 'ReactDOM',
      //   'react-router-dom': 'ReactRouterDOM',
    })
  ),
  devServer: overrideDevServer(devServerConfig),
};

